package CardDemo;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        CardDemo cardDemo =new CardDemo();
        //1.买52张牌
        List<Card>cardList =cardDemo.buyCard();
        System.out.println(cardList);
        //2.洗牌
        cardDemo.shuffle(cardList);
        System.out.println(cardList);
        //3.3个人 每个人 轮流揭牌5张
        List<List<Card>>ret =cardDemo.play(cardList);
        for (int i = 0; i < ret.size(); i++) {
            System.out.println("第"+(i+1)+"个人的牌"+ret.get(i));
        }
        System.out.println("剩下的牌");
        System.out.println(cardList);
    }
    public static  List<List<Integer>>genarte(int numRows){
        List<List<Integer>> ret =new ArrayList<>();
        List<Integer>list =new ArrayList<>();
        list.add(1);
        ret.add(list);
        //从第二行开始，进行求每个元素
        for (int i = 1; i < numRows; i++) {
            //处理第一个元素
            List<Integer>curRow =new ArrayList<>();
            curRow.add(1);
            //中间
            List<Integer>preRow =ret.get(i-1);
            for(int j=1;j<i;j++){
                int val1 =preRow.get(j);
                int val2 =preRow.get(j-1);
                curRow.add(val1+val2);
            }
            //尾巴
            curRow.add(1);
            ret.add(curRow);
        }
        return  ret;
    }
    public static void main6(String[] args) {
        List<List<Integer>>ret =genarte(4);
        for (int i = 0; i < ret.size(); i++) {
            for(int j=0;j<ret.get(i).size();j++){
                System.out.print(ret.get(i).get(j)+" ");
            }
            System.out.println();
        }
    }
    public static void main5(String[] args) {
        String str1 ="welcome to bit";
        String  str2 ="come";
        ArrayList <Character> ret = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch =str1.charAt(i);
            if(!str2.contains(ch+"")){
                ret.add(ch);
            }
        }
        for (int i = 0; i < ret.size(); i++) {
            System.out.print(ret.get(i));
        }
        System.out.println();
        //System.out.println(ret);
    }
    public static void main4(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println(list);
        System.out.println("====使用迭代器 listIterator 输出 拓展");
        ListIterator<Integer>it =list.listIterator(list.size());
        while(it.hasPrevious()){
            System.out.print(it.previous()+" ");
        }
        System.out.println();
        System.out.println("======使用迭代器iterator输出====");
        Iterator<Integer>it1 =list.iterator();
        while(it1.hasNext()){
            System.out.print(it1.next()+" ");
        }
        System.out.println();
        System.out.println("=========使用迭代器listIterator输出====");
        ListIterator<Integer>it2 =list.listIterator();
        while(it2.hasNext()){
            System.out.print(it2.next()+" ");
        }
        System.out.println();
        int size =list.size();
        System.out.println("====for循环输出===");
        for (int i = 0; i < size; i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("=====for each循环输出===");
        for (Integer x:list){
            System.out.print(x+" ");
        }
        System.out.println();
    }
    public static void main3(String[] args) {
        ArrayList  <Integer> list =new ArrayList<>(12);
        list.add(22);
        list.add(21);
        list.add(33);
        list.add(45);
        System.out.println(list);
        System.out.println("======");
        ArrayList<Integer> list1 =new ArrayList<>();
        list1.add(2);
        list1.add(1);
        list1.add(3);
        list1.add(9);
        list1.add(1,99);
        list1.add(77);
        list1.addAll(list);
        System.out.println(list1);
        ArrayList<Integer> ret = new ArrayList<>(list);
        List<Integer> list2 =new ArrayList<>();

    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        //注意hashNext和hashLine的区别
        while(in.hasNext()){
            //注意while 处理多个case
            String str =in.nextLine();
            System.out.println(func(str));
        }
    }
    //编程题2
    private static  String func(String str){
        boolean[] flg =new boolean[127];//默认都是false
        StringBuilder stringBuilder =new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char ch =str.charAt(i);
            if(flg[ch]==false){
                stringBuilder.append(ch);
                flg[ch] =true;
            }
        }
        return stringBuilder.toString();
    }
    //SE语法试卷中的编程题2
    public void merge(int[]num1,int m,int []num2,int n){
        int i=m-1;
        int j=n-1;
        int k=m+n-1;
        while(i>=0 && j>=0){
            if(num1[i]>num2[j]){
                num1[k--]=num1[i--];
            }else{
                num1[k--]=num2[j--];
            }
        }
        while(i>=0){
            num1[k--]=num1[i--];
        }
        while(j>=0){
            num1[k--]=num2[j--];
        }
    }
    public static void main1(String[] args) {
         ArrayList<String> list =new ArrayList<>();
        list.add("Java课程");
        list.add("JavaSE");
        list.add("JavaEE");
        list.add("JavaWeb");
        System.out.println(list);
        //获取list中的元素个数
        System.out.println(list.size());
        // 获取和设置index位置上的元素，注意index必须介于[0, size)间
        //System.out.println(list.get(1));
        System.out.println(list.set(1,"JavaJVM"));
        System.out.println(list.get(1));
        // 在list的index位置插入指定元素，index及后续的元素统一往后搬移一个位置
        list.add(1,"Java多线程");
        System.out.println(list);
        // 删除指定元素，找到了就删除，该元素之后的元素统一往前搬移一个位置
        list.remove(1);
        System.out.println(list);
        // 删除list中index位置上的元素，注意index不要超过list中有效元素个数,否则会抛出下标越界异常
        list.remove(list.size()-1);
        System.out.println(list);
        // 检测list中是否包含指定元素，包含返回true，否则返回false
        if(list.contains("测试工程")){
           list.add("测试工程");
            System.out.println(list);
        }
        // 查找指定元素第一次出现的位置：indexOf从前往后找，lastIndexOf从后往前找
        list.add("JavaSE");
        System.out.println(list.indexOf("JavaSE"));
        System.out.println(list.lastIndexOf("JavaSE"));
        // 使用list中[0, 4)之间的元素构成一个新的SubList返回,但是和ArrayList共用一个elementData数组
        List<String> ret = list.subList(1,3);
        System.out.println(ret);
        list.clear();
        System.out.println(list.size());
    }
}
